using System.Collections;
using UnityEngine;

public class UIAnimTools
{
	public static IEnumerator DoFillFromTo(UISprite sprite, float from, float to, float duration)
	{
		float time = 0f;
		while (time < duration)
		{
			time += RealTime.deltaTime;
			float normTime = time / duration;
			sprite.fillAmount = Mathf.Lerp(from, to, normTime);
			yield return null;
		}
		sprite.fillAmount = to;
	}

	public static IEnumerator DoWaitRealTime(float duration)
	{
		float time = 0f;
		while (time < duration)
		{
			time += RealTime.deltaTime;
			yield return null;
		}
	}

	public static IEnumerator DoFillLabelFromTo(UILabel label, int from, int to, string stringTemplate, float duration)
	{
		float time = 0f;
		if (duration > 0f)
		{
			while (time < duration)
			{
				time += RealTime.deltaTime;
				float normTime = time / duration;
				label.text = string.Format(stringTemplate, (int)Mathf.Lerp(from, to, normTime));
				yield return null;
			}
		}
		label.text = string.Format(stringTemplate, to);
	}

	public static IEnumerator DoScaleFromTo(UIWidget widget, Vector3 from, Vector3 to, float duration)
	{
		float time = 0f;
		if (duration > 0f)
		{
			while (time < duration)
			{
				time += RealTime.deltaTime;
				float normTime = time / duration;
				widget.cachedTransform.localScale = Vector3.Lerp(from, to, normTime);
				yield return null;
			}
		}
		widget.cachedTransform.localScale = to;
	}

	public static IEnumerator DoMoveFromTo(Transform transform, Vector3 from, Vector3 to, float duration, AnimationCurve curve)
	{
		float time = 0f;
		if (duration > 0f)
		{
			while (time < duration)
			{
				time += RealTime.deltaTime;
				float normTime = time / duration;
				if (curve != null)
				{
					normTime = curve.Evaluate(normTime);
				}
				transform.localPosition = Vector3Ex.LerpNotClamped(from, to, normTime);
				yield return null;
			}
		}
		transform.localPosition = to;
	}

	public static IEnumerator DoFadeFromTo(UIWidget widget, float from, float to, float duration)
	{
		float time = 0f;
		if (duration > 0f)
		{
			while (time < duration)
			{
				time += RealTime.deltaTime;
				float normTime = time / duration;
				widget.alpha = Mathf.Lerp(from, to, normTime);
				yield return null;
			}
		}
		widget.alpha = to;
	}

	public static IEnumerator DoRealTimeWait(float duration)
	{
		float time = 0f;
		if (duration > 0f)
		{
			while (time < duration)
			{
				time += RealTime.deltaTime;
				yield return null;
			}
		}
	}
}
